import axios, {ResDataType} from "./ajax";

type SearchOption = {
    keyword: string
    isStar: boolean
    isDeleted: boolean
    page: number
    pageSize: number
}
// 获取单个问卷信息
export const getQuestionService = async (id: string): Promise<ResDataType> => {
    return await axios.get(`/api/question/${id}`)
}

// 创建问卷
export const createQuestionService = async (): Promise<ResDataType> => {
    return await axios.post('/api/question')
}

// 获取（查询）问卷列表
export async function getQuestionListService(opt: Partial<SearchOption>): Promise<ResDataType> {
    return (await axios.get('/api/question', {params: opt})) as ResDataType
}

// 更新单个问卷
export async function updateQuestionService(id: string, opt: { [key: string]: any }): Promise<ResDataType> {
    return await axios.patch(`/api/question/${id}`, opt)
}

// 复制问卷
export async function duplicateQuestionService(id: string): Promise<ResDataType> {
    return await axios.post(`/api/question/duplicate/${id}`)
}

// 批量彻底删除
export async function deleteQuestionService(ids: string[]): Promise<ResDataType> {
    return await axios.delete('/api/question', {data: {ids}})
}